<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <title>07-如何改变Promise实例的状态</title>
</head>

<body>
  <!-- 1. 如何改变 promise 的状态 ?
      (1) resolve(value): 如果当前是 pending 就会变为 resolved
      (2) reject(reason): 如果当前是 pending 就会变为 rejected
      (3) 抛出异常: 如果当前是 pending 就会变为 rejected
   -->

  <script>
    new Promise((resolve, reject) => {
      // resolve('成功的value');    
      // console.log(a); //引擎抛出异常   失败原因：ReferenceError: a is not defined
      throw new Error('出错了');  //用户手动抛出异常   失败原因：Error: 出错了
    }).then(
      (value) => { console.log('成功的value：' + value); },
      (reason) => { console.log('失败原因：' + reason); }
    )
  </script>
</body>

</html>